import { ShInput } from './ShInput'

const AmountPattern = new RegExp(/^-?(\d+(\.\d{0,2})?)?$/)

export class ShAmountInput extends ShInput {

    private _lastValue: string

    constructor() {
        super()

        this._lastValue = ''
        this.$input.on('input', () => {
            if (AmountPattern.test(this.value))
                this._lastValue = this.value
            else
                this.value = this._lastValue
        })
    }
}
customElements.define('sh-amount-input', ShAmountInput)